﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	public class ActionProduceMarauder : ActionProduceTerran
	{
		public static ActionProduceMarauder Instance = new ActionProduceMarauder();

		private ActionProduceMarauder() : base(30, 100, 25, 2) { }

		public override int AvailableProducer(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return (state.BarracksTechLab.AvailableForProduction);
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.BarracksTechLab.Count > 0;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || state.BarracksTechLab.Total == 0;
		}

		public void OnProductionFinished(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			state.Marauder++;
		}

		public override void Execute(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			base.Execute(bo);
			state.BarracksTechLab.Production++;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnMarauder", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				TerranState ibostate = ibo.State as TerranState;
				ibostate.BarracksTechLab.Production--;
				OnProductionFinished(ibo);
			}));
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
				{
					m_Requirements = new IAction[,] { 
						{ ActionProduceTechLabOnBarracks.Instance }, 
						{ ActionSwitchTechLabFromFactoryToBarracks.Instance }, 
						{ ActionSwitchTechLabFromStarportToBarracks.Instance }, 
					};
				}
				return m_Requirements;
			}
		}

	}
}
